package com.accloud.service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ACMessageOption {
    public static short ZC_OPT_APPDIRECT = 1;
    public static short ZC_OPT_TRANSPORT = 0;
    byte[] OptBytes;
    short OptCode;
    short OptLen;

    public static byte[] getZMessageOptionBytes(List<ACMessageOption> zMessageOptionList) {
        int length = 0;
        List<byte[]> bMsgOptList = new ArrayList<>();
        for (ACMessageOption zMessageOption : zMessageOptionList) {
            int length2 = length + zMessageOption.getOptLen() + 4;
            byte[] bMsgOpt = new byte[(zMessageOption.getOptLen() + 4)];
            short2Byte(zMessageOption.getOptCode(), bMsgOpt, 0);
            short2Byte(zMessageOption.getOptCode(), bMsgOpt, 2);
            System.arraycopy(zMessageOption.getOptBytes(), 0, bMsgOpt, 4, zMessageOption.getOptLen());
            bMsgOptList.add(bMsgOpt);
            length = length2 + zMessageOption.getOptLen() + 4;
        }
        byte[] bytes = new byte[length];
        int offset = 0;
        for (byte[] bMsgOpt2 : bMsgOptList) {
            System.arraycopy(bMsgOpt2, 0, bytes, offset, bMsgOpt2.length);
            offset += bMsgOpt2.length;
        }
        return bytes;
    }

    /* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: int */
    /* JADX WARN: Multi-variable type inference failed */
    public static List<ACMessageOption> getZMessageOption(short length, byte[] bMessageOption) {
        List<ACMessageOption> zMessageOptionList = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            ACMessageOption zMessageOption = new ACMessageOption();
            zMessageOption.setOptCode(new BigInteger(new byte[]{bMessageOption[0], bMessageOption[1]}).shortValue());
            short shortValue = new BigInteger(new byte[]{bMessageOption[2], bMessageOption[3]}).shortValue();
            zMessageOption.setOptLen(shortValue);
            byte[] optMsg = new byte[shortValue];
            System.arraycopy(bMessageOption, 4, optMsg, 0, shortValue);
            zMessageOption.setOptBytes(optMsg);
            zMessageOptionList.add(zMessageOption);
            System.arraycopy(bMessageOption, shortValue + 4, bMessageOption, 0, (bMessageOption.length - 4) - shortValue);
        }
        return zMessageOptionList;
    }

    public static void short2Byte(short a, byte[] b, int offset) {
        b[offset] = (byte) (a >> 8);
        b[offset + 1] = (byte) a;
    }

    public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) {
        byte[] byte_3 = new byte[(byte_1.length + byte_2.length)];
        System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
        System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
        return byte_3;
    }

    public byte[] byte3Merger(byte[] byte_1, byte[] byte_2, byte[] byte_3) {
        byte[] byte_4 = new byte[(byte_1.length + byte_2.length + byte_3.length)];
        System.arraycopy(byte_1, 0, byte_4, 0, byte_1.length);
        System.arraycopy(byte_2, 0, byte_4, byte_1.length, byte_2.length);
        System.arraycopy(byte_3, 0, byte_4, byte_1.length + byte_2.length, byte_3.length);
        return byte_4;
    }

    public short getOptCode() {
        return this.OptCode;
    }

    public void setOptCode(short optCode) {
        this.OptCode = optCode;
    }

    public short getOptLen() {
        return this.OptLen;
    }

    public void setOptLen(short optLen) {
        this.OptLen = optLen;
    }

    public byte[] getOptBytes() {
        return this.OptBytes;
    }

    public void setOptBytes(byte[] optBytes) {
        this.OptBytes = optBytes;
    }

    public String toString() {
        return "ACMessageOption{OptCode=" + ((int) this.OptCode) + ", OptLen=" + ((int) this.OptLen) + ", OptBytes=" + Arrays.toString(this.OptBytes) + '}';
    }
}
